import Taro, { Component } from '@tarojs/taro';
import { View, Text, Button } from '@tarojs/components';
import UsedCardRecordFunction from '../../../components/vip-card-record-function';
import NavigationBar from '../../../components/navigationBar/index';
import Time from '../../../static/card/icon_time.png';
import { editagentList } from '../../../services/card';

import './index.scss';

export default class Index extends Component {

  config = {
    navigationBarTitleText: '',
    enablePullDownRefresh: true,
  }

  state = {
    type: 0, // 0 静止状态 1 pulldown 2 reachBottom
    navigationBarHeight: Taro.getStorageSync('navigationBarHeight'),
    viplist: null,
    member_proportion: '',
    level_nickname: '',
  }

  componentWillMount() {
    this.setState({
      member_proportion: JSON.parse(this.$router.params.viplist).member_proportion,
    })
    this.setState({
      level_nickname: JSON.parse(this.$router.params.viplist).level_nickname,
    })
  }
  componentDidMount() { }
  componentWillReceiveProps(nextProps, nextContext) { }
  componentWillUnmount() { }
  componentDidShow() { }
  componentDidHide() { }
  componentDidCatchError() { }
  componentDidNotFound() { }
  handleText(key,e) {
    this.setState({
      level_nickname: e.detail.value,
    })
  }
  handleTexts(key,e) {
    this.setState({
      member_proportion: e.detail.value,
    })
  }
  search() {
    var pagedata = {
      id:JSON.parse(this.$router.params.viplist).id,
      level_nickname:this.state.level_nickname,
      member_proportion:parseInt(this.state.member_proportion)
    }
    console.log(pagedata)
    editagentList({
      ...pagedata
    }).then(res => {
      Taro.showToast({
        title: '修改成功!',
        icon: 'none'
      });
      setTimeout(() => {
        Taro.navigateBack();
      }, 1000);
    });
  }
  render() {
    return (
      <View className='card' style={`margin-top: ${navigationBarHeight}`}>
        <NavigationBar text='编辑代理商' type="activity" />
        {/* <View className="card-line">
          <Image src={Time} alt="" className="icon" />
          <View>状态：{viplist.status}</View>
        </View> */}
        <View className="card-line">
          <View>佣金比例：
            <Input className="input-item" placeholder-class="phcolor" value={member_proportion} onInput={(e) => this.handleTexts('receiver', e)} placeholder="请输入佣金比例" />
          </View>
        </View>
        <View className="card-line">
          <View>代理商编号：
            <Input className="input-item" placeholder-class="phcolor" value={level_nickname} onInput={(e) => this.handleText('receiver', e)} placeholder="请输入代理商编号" />
          </View>
        </View>
        <Button className='dec_btn' onClick={this.search}>
          确定
        </Button>
        {/* {
   
        }
        <View className="card-line" >
          <Image src={Kind} alt="" className="icon" />
          {(!type) && <View>兑换规格：{sku}</View>}
          {(type) && <View>类型：{cardType}</View>}
        </View>
        {
          (type === 6) && <View className="card-line" >
            <Image src={Agengcy} alt="" className="icon" />
            <View>代理：{agency}</View>
          </View>
        } */}
      </View>

    );
  }
}
